package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.entity.Invite;
import com.century.sjt.util.Constant;

import java.util.List;

/**
 * 邀请适配器
 */
public class InviteAdapter extends BaseAdapter{
    private List<Invite> mDataList;
    private LayoutInflater mLayoutInflater;
    private Context context;

    public InviteAdapter(Context context, List<Invite> mDataList, RequestQueue mQueu){
        this.mDataList=mDataList;
        this.context=context;
        mLayoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            //由于我们只需要将XML转化为View，并不涉及到具体的布局，所以第二个参数通常设置为null
            convertView = mLayoutInflater.inflate(R.layout.sjt_inprople_ltem, null);
            holder.imgUser= (ImageView) convertView.findViewById(R.id.inpeople_touxiang_image);
            holder.tvAmount= (TextView) convertView.findViewById(R.id.inpeople_amount);
            holder.tvName= (TextView) convertView.findViewById(R.id.inpeople_name);
            holder.tvTime= (TextView) convertView.findViewById(R.id.inpeople_time);
            holder.tvPhome=(TextView)convertView.findViewById(R.id.inpeople_phome);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Invite mInvite=mDataList.get(i);
        if ("".equals(mInvite.getName().toString().trim())||null==mInvite.getName().toString()){
            holder.tvName.setVisibility(View.GONE);
        }else {
            holder.tvName.setText(mInvite.getName());
        }

        holder.tvAmount.setText("￥"+mInvite.getInvitedAmount());
        holder.tvTime.setText(mInvite.getRegTime());
        holder.tvPhome.setText(mInvite.getMobile());
        Glide.with(context).load(Constant.BaseImageUrl+mInvite.getImage()).into(holder.imgUser);
//        holder.imgUser.setImageURI(mInvite.getImage().toString());

        return convertView;
    }

    // ViewHolder用于缓存控件
    static class ViewHolder {
        private ImageView imgUser;//用户头像
        private TextView tvAmount;//奖金
        private TextView tvName;//用户名
        private TextView tvTime;//邀请时间
        private TextView tvPhome;//电话
    }
}
